package com.huizu.goods.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.huizu.common.annotation.Log;
import com.huizu.common.enums.BusinessType;
import com.huizu.goods.domain.ShopOrder;
import com.huizu.goods.domain.ShopOrderDetail;
import com.huizu.goods.service.IShopOrderService;
import com.huizu.common.core.controller.BaseController;
import com.huizu.common.core.domain.AjaxResult;
import com.huizu.common.utils.ShiroUtils;
import com.huizu.common.utils.poi.ExcelUtil;
import com.huizu.common.core.page.TableDataInfo;

/**
 * 订单主信息Controller
 * 
 * @author 
 * @date 2020-04-22
 */
@Controller
@RequestMapping("/shop/order")
public class ShopOrderController extends BaseController {
	private String prefix = "shop/order";

	@Autowired
	private IShopOrderService shopOrderService;

	@RequiresPermissions("shop:order:view")
	@GetMapping()
	public String order() {
		return prefix + "/order";
	}

	/**
	 * 查询订单主信息列表--dai
	 */
	@RequiresPermissions("shop:order:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ShopOrder shopOrder) {
		startPage();
		shopOrder.setOrderStatus("1");
		shopOrder.setShopId(ShiroUtils.getSysUser().getShopId());
		List<ShopOrder> list = shopOrderService.selectShopOrderList(shopOrder);
		return getDataTable(list);
	}
	
	/**
	 * 查询订单主信息列表
	 */
	@RequiresPermissions("shop:order:list")
	@PostMapping("/list1")
	@ResponseBody
	public TableDataInfo list1(ShopOrder shopOrder) {
		startPage();
		shopOrder.setOrderStatus("2");
		shopOrder.setShopId(ShiroUtils.getSysUser().getShopId());
		List<ShopOrder> list = shopOrderService.selectShopOrderList(shopOrder);
		return getDataTable(list);
	}
	
	/**
	 * 查询订单主信息列表
	 */
	@RequiresPermissions("shop:order:list")
	@PostMapping("/list2")
	@ResponseBody
	public TableDataInfo list2(ShopOrder shopOrder) {
		startPage();
		shopOrder.setOrderStatus("3");
		shopOrder.setShopId(ShiroUtils.getSysUser().getShopId());
		List<ShopOrder> list = shopOrderService.selectShopOrderList(shopOrder);
		return getDataTable(list);
	}
	
	/**
	 * 查询订单主信息列表
	 */
	@RequiresPermissions("shop:order:list")
	@PostMapping("/list3")
	@ResponseBody
	public TableDataInfo list3(ShopOrder shopOrder) {
		startPage();
		shopOrder.setOrderStatus("4,5");
		shopOrder.setShopId(ShiroUtils.getSysUser().getShopId());
		List<ShopOrder> list = shopOrderService.selectShopOrderList(shopOrder);
		return getDataTable(list);
	}

	@PostMapping("/listChile")
	@ResponseBody
	public TableDataInfo listChile(ShopOrder shopOrder) {
		List<ShopOrderDetail> list = shopOrderService.getlistChile(shopOrder);
		return getDataTable(list);
	}

	/**
	 * 导出订单主信息列表
	 */
	@RequiresPermissions("shop:order:export")
	@Log(title = "订单主信息", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(ShopOrder shopOrder) {
		List<ShopOrder> list = shopOrderService.selectShopOrderList(shopOrder);
		ExcelUtil<ShopOrder> util = new ExcelUtil<ShopOrder>(ShopOrder.class);
		return util.exportExcel(list, "order");
	}

	/**
	 * 新增订单主信息
	 */
	@GetMapping("/add")
	public String add() {
		return prefix + "/add";
	}

	/**
	 * 新增保存订单主信息
	 */
	@RequiresPermissions("shop:order:add")
	@Log(title = "订单主信息", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ShopOrder shopOrder) {
		return toAjax(shopOrderService.insertShopOrder(shopOrder));
	}

	/**
	 * 修改订单主信息
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap) {
		ShopOrder shopOrder = shopOrderService.selectShopOrderById(id);
		mmap.put("shopOrder", shopOrder);
		return prefix + "/edit";
	}

	/**
	 * 修改保存订单主信息
	 */
	@RequiresPermissions("shop:order:edit")
	@Log(title = "订单主信息", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ShopOrder shopOrder) {
		return toAjax(shopOrderService.updateShopOrder(shopOrder));
	}

	/**
	 * 删除订单主信息
	 */
	@RequiresPermissions("shop:order:remove")
	@Log(title = "订单主信息", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(shopOrderService.deleteShopOrderByIds(ids));
	}
	
	/**
	 * 删除订单主信息
	 */
	@PostMapping("/getExpress")
	@ResponseBody
	public List<Map<String,Object>>  getExpress() {
		return shopOrderService.getExpress();
	}
}
